import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  mailBoxList: {},
  mailBoxLists: {},
  currentMailBox: {}
};

const getters = {
  mailBoxList: state => state.mailBoxList,
  mailBoxLists: state => state.mailBoxLists,
  currentMailBox: state => state.currentMailBox
};

const actions = {
  // 领导信箱列表
  mailListUsingPOSTS({ commit }, param) {
    return Api.mailListUsingPOST(param).then(ret => {
      commit(types.UPDATE_MAIL_BOX_LIST, ret.data);
      return ret;
    });
  },
  // 领导信箱详情
  getMailBoxUsingPOSTS({ commit }, param) {
    return Api.getMailBoxUsingPOST(param).then(ret => {
      commit(types.UPDATE_MAIL_BOX_LISTS, ret.data);
      return ret;
    });
  },
  // 领导信箱审核
  examineMailBoxUsingPOSTS({ commit }, param) {
    return Api.examineMailBoxUsingPOST(param).then(ret => {
      return ret;
    });
  },
  // 领导信箱删除
  delMailUsingPOST_1S({ commit }, param) {
    return Api.delMailUsingPOST(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.UPDATE_MAIL_BOX_LIST](state, payload) {
    state.mailBoxList = payload;
  },
  // [types.INIT_CURRENT_COLUMN](state) {
  //   state.currentColumn = {
  //     name: "",
  //     sort: 0
  //   };
  // },
  // [types.UPDATE_CURRENT_COLUMN](state, payload) {
  //   state.currentColumn = payload;
  // },
  [types.UPDATE_MAIL_BOX_LISTS](state, payload) {
    state.mailBoxLists = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
